import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
// 应用初始状态
const state = {
  options: [{name: "首页",route: "/index"}],
  activeIndex: '/index',
  callFlag: false,//坐席登录状态
}

// 定义所需的 mutations
const mutations = {
  // 添加tabs
  add_tabs (state, data) {
    this.state.options.push(data);
  },
  // 删除tabs
  delete_tabs (state, route) {
    let index = 0;
    for (let option of state.options) {
      if (option.route === route) {
        break;
      }
      index++;
    }
    this.state.options.splice(index, 1);
  },
  // 设置当前激活的tab
  set_active_index (state, index) {
    this.state.activeIndex = index;
  },
  // 设置坐席登录状态
  setCallFlag(state, flag){
    this.state.callFlag = flag;
  },
}

// 创建 store 实例
export default new Vuex.Store({
  state,
  mutations
})
